<template>
	<view>
		<view class="my-friend">我的好友</view>
		<block v-for="(item, index) in friendList" :key="index">
			<fun-friend-item :friend="item" @clickRight="clickRight(item.uid)" @clickLeft="clickLeft(item.uid)"></fun-friend-item>
		</block>
	</view>
</template>

<script>
	import {Friend} from '@/model/friend.js';
	import funFriendItem from '@/components/funFriendItem/funFriendItem.vue';
	export default {
		data() {
			return {
				friendList:[],
			}
		},
		components:{
			funFriendItem
		},
		async onLoad() {
			let res = await Friend.getFriendList()
			this.friendList = res.data
		},
		methods: {
			clickRight(uid){
				let _this = this
				uni.navigateTo({
					url:"../chatRoom/chatRoom",
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						res.eventChannel.emit('acceptDataFromOpenerPage', { friendUid: uid })
						let message = {
							uid:uid,
							toFriendId:_this.$store.user.uid,
							contentType:5,
						}
						_this.$store.socketTask.sockSend(message)
					}
				})
			},
			clickLeft(uid){
				uni.navigateTo({
					url:"../friendDetaile/friendDetaile",
					
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #F2F2F2;
	}
</style>
<style lang="scss" scoped>
	.my-friend{
		background-color: #FFF;
		padding: 20rpx 20rpx;
		font-size: 26rpx;
		color: #999999;
	}
</style>
